<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2022/10/13
  Time: 14:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/adminlogin.css" >
</head>
<body>
<div class="wrap">
    <img src="img/login.jpg" class="imgStyle">
    <div class="loginForm">
        <form class="layui-form">
            <div class="logoHead">
                <!--<h2 style="margin-top: 15px">房产销售平台管理系统</h2>-->
            </div>
            <div class="usernameWrapDiv">
                <div class="usernameLabel">
                    <label>用户名:</label>
                </div>
                <div class="usernameDiv">
                    <i class="layui-icon layui-icon-username adminIcon"></i>
                    <input id="loginUsername" lay-verify="required" value="admin" class="layui-input adminInput" type="text" name="username" placeholder="输入用户名" >
                </div>
            </div>
            <div class="usernameWrapDiv">
                <div class="usernameLabel">
                    <label>密码:</label>
                </div>
                <div class="passwordDiv">
                    <i class="layui-icon layui-icon-password adminIcon"></i>
                    <input id="loginPassword" lay-verify="required" value="admin" class="layui-input adminInput" type="password" name="password" placeholder="输入密码">
                </div>
            </div>
            <div class="usernameWrapDiv">
                <div class="usernameLabel">
                    <label>验证码:</label>
                </div>
                <div class="cardDiv">
                    <input id="loginCard" lay-verify="required|validatecode" value="test" class="layui-input cardInput" type="text" name="card" placeholder="输入验证码">
                </div>
                <div class="codeDiv">
                    <input id="loginCode" class="layui-input codeInput"  type="button">
                </div>
            </div>
            <div class="usernameWrapDiv">
<%--                <div class="submitLabel">--%>
<%--                    <label>没有账号？<a href="#" id="loginRegister">点击注册</a></label>--%>
<%--                </div>--%>
                <div class="submitDiv">
                    <button type="submit" class="submit layui-btn layui-btn-primary" lay-submit="" lay-filter="loginUser" >登录</button>
<%--                    <input id="loginBtn" type="button" class="submit layui-btn layui-btn-primary" value="登录"></input>--%>

                </div>
            </div>
        </form>
    </div>
</div>
<script type="application/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script>
    var $;
    var namestatus=true;
    layui.use(['layer','jquery'],function () {
        var layer = layui.layer
            , upload = layui.upload
            ,form=layui.form
            , element = layui.element
        ;
        $=layui.jquery;
        // 验证码切换
        $('#loginCode').click(function () {
            createCode('#loginCode');
        });

        // 注册事件
        $('#loginRegister').click(function () {
            register();
        });
        createCode('#loginCode');



        // 自定义校验  验证码要正确
        form.verify({
            // pass 给校验起的的名字   回调函数  （value）
            validatecode: function(value){ //自定义lay-verify的昵称，value：表单的值
                // 输入的验证码 value
                // 卡片里面的验证码 loginCode
                var cardCode=$("#loginCode").val();
                // 不区分大小写
                var newval = value.toUpperCase();// 将我们输入的验证码全部转为大写
                if(newval!=cardCode){
                    if(newval!='TEST'){// 只在开发的过程中使用   上线的时候不能用
                        return "请输入正确的验证码！";
                    }

                }
            }
        });



        // 提交登录
        form.on('submit(loginUser)',function(data){
            //alert(JSON.stringify(data.field));
            $.ajax({
                url:"${pageContext.request.contextPath}/login",
                data:data.field,
                type:"post",
                success:function(d){
                    //{code   msg    data}
                    if(d.data==true){
                        window.location="${pageContext.request.contextPath}/tMenu";
                        // 登录页面
                        // layer.msg('注册成功！', {icon: 1});
                        <%--window.location="${pageContext.request.contextPath}/views/login.jsp";--%>
                    }else{
                        layer.msg("登录失败",{icon:2})
                    }

                }
            })

            return false;
        })

    })
    // 页面初始化生成验证码

    // 生成验证码
    function createCode(codeID) {
        var code = "";
        // 验证码长度
        var codeLength = 4;
        // 验证码dom元素
        var checkCode = $(codeID);
        // 验证码随机数
        var random = [0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R',
            'S','T','U','V','W','X','Y','Z'];
        for (var i = 0;i < codeLength; i++){
            // 随机数索引
            var index = Math.floor(Math.random()*36);
            code += random[index];
        }
        // 将生成的随机验证码赋值
        checkCode.val(code);
    }







</script>
</body>



</html>

